//index.js
//获取应用实例
const app = getApp()
var common = require("../../common.js")
Page({
  data: {}, 
  onLoad: function () { 
    this.setData({
      userInfo:app.globalData.userInfo
    });

	wx.showLoading({
		title:'正在加载数据',
	})
    var that=this;
    common.request(
      {
        url: 'c=Game&a=getMyGame',
        success: function (re) {
          that.setData({
            myGame: re.list,
            point:re.uinfo.point,
            imcomeMoney: ((parseInt(re.uinfo.depositMoney) + parseInt(re.uinfo.cashMoney))/100).toFixed(2),
            depositMoney: (re.uinfo.depositMoney / 100).toFixed(2),
          });       
        },
        fail: function (re) { },
        complete: function (re) {
			wx.hideLoading();
		}
      }
    );

  },
  cashTap:function(e){
    if (this.data.depositMoney<1){
      wx.showToast({
        title: '抱歉，可提现金额大于1元时才可提现',
      })
    }else{
      var that=this;
      wx.showModal({     
        content: '提现金额将即时打入您的微信钱包，确定进行提现操作吗?',
        success: function (res) {
          if (res.confirm) {
            wx.showLoading({
              title: '正在提交请求',
			  mask:true,
            })
            common.request(
              {
                url: 'c=Game&a=cash',
                success: function (re) {
                  if(re.status==0){
                    that.setData({
                      //imcomeMoney: ((parseInt(re.uinfo.depositMoney) + parseInt(re.uinfo.cashMoney)) / 100).toFixed(2),
                      depositMoney: 0,
                    })
                  }
                    wx.showModal({
                     
                      content: re.msg,
                      showCancel:false
                      })
                  
                },
                fail: function (re) { },
                complete: function (re) {
                  wx.hideLoading();
                 }
              }
            );


          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    }
    
  },
  gameTap:function(e){
    const id=e.currentTarget.dataset.id;
    wx.navigateTo({
      url: 'detail?id='+id,
    })
  },
  surenTap: function () {
    wx.navigateTo({
      url: '../../pages/suren/index',
    })
  },
  logTap:function(){
    wx.navigateTo({
      url: '../../pages/suren/gotlog',
    })
  }
})



